﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml.Serialization;

namespace SyncTool
{
    public class SyncPlan
    {
        public string Name { get; set; }
        public string Source { get; set; }
        public string Desination { get; set; }
        public string ExcludeKeywords { get; set; }
    }

    public static class SyncPlanHelper
    { 
        static readonly string strFile = AppDomain.CurrentDomain.BaseDirectory + "SyncPlan.xml";

        public static void Save(SyncPlan plan)
        {
            try
            {
                using (FileStream fs = new FileStream(strFile, FileMode.Create))
                {
                    XmlSerializer formatter = new XmlSerializer(typeof(SyncPlan));
                    formatter.Serialize(fs, plan);
                }
            }
            catch { return; }
        }

        public static SyncPlan Read()
        {
            SyncPlan plan = null;
            if (!File.Exists(strFile)) return plan;
            try
            {
                using (FileStream fs = new FileStream(strFile, FileMode.Open))
                {
                    XmlSerializer formatter = new XmlSerializer(typeof(SyncPlan));
                    plan = (SyncPlan)formatter.Deserialize(fs);
                }
            }
            catch { return plan; }
            return plan;
        }
    }
}
